<%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2021-07-16
  Time: 15:46
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="utf-8">
    <title>员工审核</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"  media="all">
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form" action="">
    <div class="layui-form-item">
        <div class="layui-inline">
            <div class="layui-input-inline">
                <select name="branchid" lay-search="" id="branchTid">
                    <option value="">门店</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <div class="layui-input-inline">
                <button type="button" class="layui-btn" lay-submit="" lay-filter="search">搜索</button>
            </div>
        </div>
    </div>
</form>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <%--<button class="layui-btn layui-btn-sm" lay-event="getCheckData">获取选中行数据</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
        <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>--%>
    </div>
</script>

<script type="text/html" id="barDemo">
    {{#  if(d.state == 1){ }}
    <button type="button" class="layui-btn layui-btn-normal layui-btn-sm" lay-event="adopt">通过</button>
    <button type="button" class="layui-btn layui-btn-danger layui-btn-sm" lay-event="reject">驳回</button>
    {{#  } else { }}

    {{#  } }}
</script>
<script type="text/html" id="titleTpl">
    {{#  if(d.state == 1){ }}
    <button class="layui-btn layui-btn-warm layui-btn-sm" style="width: 70px">待审核</button>
    {{# } else if(d.state == 2){ }}
    <button class="layui-btn layui-btn-sm"  style="width: 70px">申请通过</button>
    {{#  } else { }}
    <button class="layui-btn layui-btn-danger layui-btn-sm"style="width: 70px">申请驳回</button>
    {{#  } }}
</script>

<script src="${pageContext.request.contextPath}/layui/layui.js" charset="utf-8"></script>
<!-- 注意：如果你直接复制所有代码到本地，上述 JS 路径需要改成你本地的 -->

<script>
    layui.use(['table','form','jquery','layer'], function(){
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;

        //搜索填充
        window.onload=function (){ //页码加载完毕后执行的函数$(function(){})
            getAllBranch();
        }
        function getAllBranch(){
            $.ajax({
                url:"${pageContext.request.contextPath}/branch/findAll",
                typeP:"post",
                async:false,//ajax异步交互，async：false是同步提交
                success:function (result) {
                    var type=result.data;
                    var str="<option value=''>选择门店</option>";
                    for (var i = 0; i < type.length; i++) {
                        str+="<option value='"+type[i].branchid+"'>"+type[i].branchname+"</option>"
                    }
                    $("#branchTid").html(str);
                    $("#branch_id").html(str);
                    form.render('select'); //让form表单的select标签渲染
                },
                dataType:'json'
            });
        }
        //添加表单的搜索监听事件
        form.on('submit(search)',function(data){
            //表格数据重新渲染。
            table.reload('test',{
                page: {
                    curr: 1 //重新从第 1 页开始
                },
                where: { //按照什么进行查找
                    "branchid": data.field.branchid
                }
            })
        });


        table.render({
            elem: '#test'
            ,id: 'test'
            ,url:'${pageContext.request.contextPath}/transferstaffstaff/getAll'
            ,toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            ,title: '员工平调审核表'
            ,cols: [[
                {type: 'checkbox', fixed: 'left'}
                ,{field:'id', title:'ID',fixed: 'left'}
                ,{field:'staffname', title:'员工姓名',templet: function (data) {
                        return data.staff==null?"":data.staff.staffname;
                    }}
                , {field: 'branchname', title: '原店铺',templet:function (data){
                        return data.branch==null?"":data.branch.branchname
                    }}
                , {field: 'deptname', title: '原部门',templet:function (data){
                        return data.department==null?"":data.department.deptname;
                    }}
                , {field: 'newbranchname', title: '新店铺',templet:function (data){
                        return data.newbranch==null?"":data.newbranch.branchname;
                    }}
                , {field: 'newdeptname', title: '新部门',templet:function (data){
                        return data.newdepartment==null?"":data.newdepartment.deptname;
                    }}
                ,{field:'applytime', title:'申请时间'}
                , {field: 'applyid', title: '申请人',templet:function (data){
                        return data.applystaff==null?"":data.applystaff.staffname;
                    }}
                ,{field:'extime', title:'审核时间'}
                , {field: 'applyid', title: '审核人',templet:function (data){
                        return data.exstaff==null?"":data.exstaff.staffname;
                    }}
                ,{field:'state', title:'状态',templet:'#titleTpl'}
                ,{fixed: 'right', title:'操作', toolbar: '#barDemo', width:150}
            ]]
            ,page: true
        });

        //头工具栏事件
        table.on('toolbar(test)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：'+ data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选': '未全选');
                    break;
                //自定义头工具栏右侧图标 - 提示
                case 'LAYTABLE_TIPS':
                    layer.alert('这是工具栏右侧自定义的一个图标按钮');
                    break;
            };
        });

        //监听行工具事件
        table.on('tool(test)', function(obj){
            var data = obj.data;
            console.log(obj)
            if(obj.event === 'adopt'){
                var flag=1;
                var aaa=${sessionScope.staff.branchid};
                var branchid= data.newbranchid;
                if(branchid!=aaa){
                    flag=0;
                    layer.msg("对不起,你没有权限审核该分店员工!")
                }
                if (flag==1){
                    layer.confirm("确定通过吗", function (index) {
                        $.ajax({
                            type:"post",
                            url:"${pageContext.request.contextPath}/staff/ExPass",
                            data:{"id":data.id,"newbranchid":data.newbranchid,"newdeptid":data.newdeptid,"staffid":data.staffid},
                            success: function (result) {
                                layer.closeAll();
                                if (result.code == 1) {
                                    table.reload("test");
                                    layer.msg(result.msg);
                                } else if (result.code == 2) {
                                    layer.msg(result.msg);
                                    table.reload("test");
                                }
                            }
                        })
                    })
                }
            }else if (obj.event === 'reject'){
                var flag=1;
                var aaa=${sessionScope.staff.branchid};
                var branchid= data.newbranchid;
                if(branchid!=aaa){
                    flag=0;
                    layer.msg("对不起,你没有权限审核该分店员工!")
                }
                if (flag==1){
                    layer.confirm("确定驳回申请吗?", function (index) {
                        $.ajax({
                            type:"post",
                            url:"${pageContext.request.contextPath}/staff/ExReject",
                            data:{"id":data.id,"newbranchid":data.newbranchid,"newdeptid":data.newdeptid,"staffid":data.staffid},
                            success: function (result) {
                                layer.closeAll();
                                if (result.code == 1) {
                                    table.reload("test");
                                    layer.msg(result.msg);
                                    window.parent.location.reload();
                                } else if (result.code == 2) {
                                    layer.msg(result.msg);
                                    table.reload("test");
                                }
                            }
                        })
                    })
                }
            }
        });
    });
</script>

</body>
</html>
